package cn.com.jinhao.hotline.knowledge.controller;

import cn.com.jinhao.hotline.commons.controller.BaseController;
import cn.com.jinhao.hotline.commons.util.RestResponse;
import cn.com.jinhao.hotline.commons.vo.knowledge.KnowledgeConditionRequestVO;
import cn.com.jinhao.hotline.commons.vo.knowledge.KnowledgeRequestVO;
import cn.com.jinhao.hotline.commons.vo.knowledge.PopMsgRequestVO;
import cn.com.jinhao.hotline.knowledge.service.KnowledgeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * hotline-spring-cloud
 * <p>Description: </p>
 *
 * @author ShaneMew
 * @version 1.0
 * @since 2020/7/23
 */
@RestController
@RequestMapping("knowledge")
@Api(tags = {"知识库服务"})
public class KnowledgeController extends BaseController {
    @Resource
    KnowledgeService knowledgeService;

    @ApiOperation(value = "工作台知识库搜索")
    @PostMapping("/workbench")
    public RestResponse<Object> knowledgeWorkbench(@ApiParam(name = "knowledgeRequestVO", value = "知识库查询参数")@Validated @RequestBody KnowledgeRequestVO knowledgeRequestVO, BindingResult result) throws Exception{
        validate(result);
        return new RestResponse<>(knowledgeService.queryKnowledge(knowledgeRequestVO.getContent(), knowledgeRequestVO.getPageSize(), knowledgeRequestVO.getPageNo()));
    }

    @ApiOperation(value = "菜单栏冒泡信息")
    @PostMapping("/popMsgInfo")
    public RestResponse<Object> popMsgKnowledge(@ApiParam(name = "popMsgRequestVO", value = "菜单栏冒泡信息") @Validated @RequestBody PopMsgRequestVO popMsgRequestVO, BindingResult result) throws Exception {
        validate(result);
        return new RestResponse<>(knowledgeService.popMsgKnowledge(popMsgRequestVO.getDeptCode()))  ;
    }

    @ApiOperation(value = "知识库搜索")
    @PostMapping("/selectCondition")
    public RestResponse<Object> selectKnowledge(@ApiParam(name = "knowledgeConditionRequestVO", value = "知识库搜索条件") @Validated @RequestBody KnowledgeConditionRequestVO knowledgeConditionRequestVO, BindingResult result) throws Exception {
        validate(result);
        return new RestResponse<>(knowledgeService.selectKnowledgeByCondition(knowledgeConditionRequestVO));
    }
}
